/*
ID: icerupt1
PROG: butter
LANG: C++11
*/

/* solution
 *
 *
*/
#include <fstream>
#include <iostream>

std::ifstream fin {"butter.in" };
std::ofstream fout{"butter.out"};

int const oo = 1<<27;
int const maxp = 802;
int const maxn = 502;
int map[maxp][maxp];
int cow_pos[maxn];
int n, p, c;

int main()
{
	fin >> n >> p >> c;
	for (int i = 0; i < n; i++) { fin >> cow_pos[i]; cow_pos[i]--; }
	for (int i = 0; i < p; i++) {
		for (int j = 0; j < p; j++) map[i][j] = oo;
		map[i][i] = 0;
	}
	for (int i = 0, x, y, l; i < c; i++) {
		fin >> x >> y >> l;
		x--; y--;
		map[x][y] = map[y][x] = l;
	}

	//flyoed
	for (int k = 0; k < p; k++)
		for (int i = 0; i < p; i++)
			for (int j = i+1; j < p; j++)
				if (map[i][k] + map[k][j] < map[i][j])
					map[i][j] = map[j][i] = map[i][k] + map[k][j];

	int ans = oo;
	for (int butter_pos = 0; butter_pos < p; butter_pos++) {
		int tmp = 0;
		for (int i = 0; i < n; i++) tmp += map[cow_pos[i]][butter_pos];
		if (tmp < ans) ans = tmp;
	}
	std::cout << ans << '\n';
	fout << ans << '\n';
}

